<?php
require_once dirname(__FILE__).'/include/user.php';

if(!hasLogin() or !isset($_REQUEST['act'])) exit();
if(!checkUsername($USERNAME)) return -1;

switch ($_REQUEST['act']) {
	case 'setting':
		userset($USERNAME);
		break;
	default:
		# code...
		break;
}



function userset($username){
	global $sql;
	if(isset($_POST['setting']) && is_array($_POST['setting'])){
		$_POST['setting']['noteid']=(int)$_POST['setting']['noteid'];
		$_POST['setting']['math']=isset($_POST['setting']['math'])&&$_POST['setting']['math']=='on'?1:0;
		$_POST['setting']['code']=isset($_POST['setting']['code'])&&$_POST['setting']['code']=='on'?1:0;
		$_POST['setting']['interval']=$_POST['setting']['interval']>2000?(int)$_POST['setting']['interval']:2000;//偷懒了,应该页面给提示的，这里不提示强制设置不低于2秒
		$_POST['setting']['black']=isset($_POST['setting']['black'])&&$_POST['setting']['black']=='on'?1:0;
		$json=json_encode($_POST['setting']);
		$sql->query("UPDATE note_users SET settings = '$json' WHERE username = '$username'");
		echo 'ok';
	}else{
		echo '-1';
	}
}

